function [ varargout ] = divasl_set_parameter( varargin )
% Divasl_set_parameter Setting parameters here
%   Format to use it:
%       1. Setting default parameters:
%           divasl_set_parameter('default') or divasl_set_parameter();
%       2. Setting user-defined parameters:
%           divasl_set_parameters('user','user_defined_parameters')
%
%   The output would be structure that contains all paramteters
%   OR
%   The output would be the error type if error occures, 
%       1. either to be 0, --->>> too many parameters;
%       2. either to be -1,--->>> user-defined function is not given
%       correctly;
%       3. either to be -2,--->>> pattern not correctly given;
%       4. either to be -3,--->>> the output is not correct.
%       5. either to be -4,--->>> not all necessary parameters are set
%

if nargin > 2
    disp('These parameter settings are not compatible for function divasl_set_parameter.');
    varargout{1} = 0;
    return;
end

if isempty(varargin)
    varargin{1} = 'default';
end

if ischar(varargin{1})
    switch lower( varargin{1})
        case 'default'
            varargout{1} = default_parameters();
        case 'user'
            if isempty(varargin{2})
%                 error('Please refer to the function that for setting parameters');
                varargout{1} = -1;
            elseif ischar(varargin{2})
                varargout{1} = eval(varargin{2});
                if ~isa(varargout{1},'struct')
                    varargout{1} = -3;
                end
            else
                varargout{1} = -1;
            end
        otherwise
            varargout{1} = -2;
    end
end

% Check all parameters are set
if ~isfield(varargout{1},{'path','asl_model'})
                    varargout{1} = -4;
end

end

function varargout = default_parameters( varargin )
%
% Setting path of files
    parameters.path.dir     = '/users/lyu/Documents/MATLAB/';
    parameters.path.project = 'myProject';
    parameters.path.sequence = 'pre-processing/gr_group01/su_subject01/perfusion/';
    parameters.path.prefix = 'seq_DIVASL_LY^PASLTI2';
    parameters.path.ti2 = '';
    parameters.path.names.org = 'asl_file.nii';
    parameters.path.names.align = 'rtasl_file.nii';
    parameters.path.names.coasl = 'cpwall_nrtasl_file_gm.nii';
    parameters.path.names.com0 = 'cm0_rtasl_file_gm.nii';

% Setting parameters to ASL kinetic model
%     parameters.asl_model.alpha   = 0.9; % labeling efficiency 
%     parameters.asl_model.t1      = 0.9; % Tissue spinlattice relaxation constant
%     parameters.asl_model.lambda  = 0.9; % blood/tissue water partion coefficient
%     parameters.asl_model.t1b     = 1.2;
%     parameters.asl_model.tau     = 1;   % Tau value in QUIPSS II
%     parameters.asl_model.model   = 'buxton'; % which model is using
%     
    varargout{1} = parameters;
end

